package aptech.eproject.logictics.db;

import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Set;

/**
 * The persistent class for the BRANCH database table.
 * 
 */
@Entity
@Table(name = "BRANCH")
@NamedQueries({
    @NamedQuery(name = "findBranches", query = "SELECT b FROM Branch b WHERE b.isDeleted = 'FALSE'"),
    @NamedQuery(name = "findBranchesByCity", query = "SELECT b FROM Branch b WHERE b.isDeleted = 'FALSE' AND b.city.cityName LIKE ?1"),
    @NamedQuery(name = "findBranchesByAddress", query = "SELECT b FROM Branch b WHERE b.isDeleted = 'FALSE' AND b.address LIKE ?2")
})
public class Branch implements Serializable {

    private static final long serialVersionUID = 1L;
    private int branchId;
    private String address;
    private String branchName;
    private short commissionPercent;
    private String description;
    private String email;
    private String image;
    private boolean isDeleted;
    private String phoneNumber;
    private BigDecimal unitPrice;
    private Set<Account> accounts;
    private City city;
    private Set<Delivery> deliveries1;
    private Set<Delivery> deliveries2;
    private Set<Route> routes1;
    private Set<Route> routes2;
    private Set<Vehicle> vehicles;
    private Set<Warehouse> warehouses;

    public Branch() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "BRANCH_ID")
    public int getBranchId() {
        return this.branchId;
    }

    public void setBranchId(int branchId) {
        this.branchId = branchId;
    }

    @Column(name = "ADDRESS", nullable = false)
    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "BRANCH_NAME", nullable = false)
    public String getBranchName() {
        return this.branchName;
    }

    public void setBranchName(String branchName) {
        this.branchName = branchName;
    }

    @Column(name = "COMMISSION_PERCENT", nullable = true)
    public short getCommissionPercent() {
        return this.commissionPercent;
    }

    public void setCommissionPercent(short commissionPercent) {
        this.commissionPercent = commissionPercent;
    }

    @Column(name = "DESCRIPTION", nullable = true)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "EMAIL", nullable = false)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "IMAGE", nullable = true)
    public String getImage() {
        return this.image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    @Column(name = "IS_DELETED", nullable = true)
    public boolean getIsDeleted() {
        return this.isDeleted;
    }

    public void setIsDeleted(boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    @Column(name = "PHONE_NUMBER", nullable = true)
    public String getPhoneNumber() {
        return this.phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Column(name = "UNIT_PRICE", nullable = true)
    public BigDecimal getUnitPrice() {
        return this.unitPrice;
    }

    public void setUnitPrice(BigDecimal unitPrice) {
        this.unitPrice = unitPrice;
    }

    //bi-directional many-to-one association to Account
    @OneToMany(mappedBy = "branch", fetch = FetchType.EAGER)
    public Set<Account> getAccounts() {
        return this.accounts;
    }

    public void setAccounts(Set<Account> accounts) {
        this.accounts = accounts;
    }

    public Account addAccount(Account acc) {
        getAccounts().add(acc);
        return acc;
    }

    public Account removeAccount(Account acc) {
        getAccounts().remove(acc);
        acc.setBranch(null);
        return acc;
    }

    //bi-directional many-to-one association to City
    @ManyToOne
    @JoinColumn(name = "CITY_ID", nullable = false)
    public City getCity() {
        return this.city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    //bi-directional many-to-one association to Delivery
    @OneToMany(mappedBy = "destinationBranch", fetch = FetchType.EAGER)
    public Set<Delivery> getDeliveries1() {
        return this.deliveries1;
    }

    public void setDeliveries1(Set<Delivery> deliveries1) {
        this.deliveries1 = deliveries1;
    }

    public Delivery addDelivery1(Delivery delivery) {
        getDeliveries1().add(delivery);
        return delivery;
    }

    public Delivery removeDelivery1(Delivery delivery) {
        getDeliveries1().remove(delivery);
        delivery.setDestinationBranch(null);
        return delivery;
    }

    //bi-directional many-to-one association to Delivery
    @OneToMany(mappedBy = "startBranch", fetch = FetchType.EAGER)
    public Set<Delivery> getDeliveries2() {
        return this.deliveries2;
    }

    public void setDeliveries2(Set<Delivery> deliveries2) {
        this.deliveries2 = deliveries2;
    }

    public Delivery addDelivery2(Delivery delivery) {
        getDeliveries2().add(delivery);
        return delivery;
    }

    public Delivery removeDelivery2(Delivery delivery) {
        getDeliveries2().remove(delivery);
        delivery.setStartBranch(null);
        return delivery;
    }

    //bi-directional many-to-one association to Route
    @OneToMany(mappedBy = "toBranch", fetch = FetchType.EAGER)
    public Set<Route> getRoutes1() {
        return this.routes1;
    }

    public void setRoutes1(Set<Route> routes1) {
        this.routes1 = routes1;
    }

    public Route addRoute1(Route route) {
        getRoutes1().add(route);
        return route;
    }

    public Route removeRoute1(Route route) {
        getRoutes1().remove(route);
        route.setToBranch(null);
        return route;
    }

    //bi-directional many-to-one association to Route
    @OneToMany(mappedBy = "fromBranch", fetch = FetchType.EAGER)
    public Set<Route> getRoutes2() {
        return this.routes2;
    }

    public void setRoutes2(Set<Route> routes2) {
        this.routes2 = routes2;
    }

    public Route addRoute2(Route route) {
        getRoutes2().add(route);
        return route;
    }

    public Route removeRoute2(Route route) {
        getRoutes2().remove(route);
        route.setFromBranch(null);
        return route;
    }

    //bi-directional many-to-one association to Vehicle
    @OneToMany(mappedBy = "branch", fetch = FetchType.EAGER)
    public Set<Vehicle> getVehicles() {
        return this.vehicles;
    }

    public void setVehicles(Set<Vehicle> vehicles) {
        this.vehicles = vehicles;
    }

    public Vehicle addVehicle(Vehicle vehicle) {
        getVehicles().add(vehicle);
        return vehicle;
    }

    public Vehicle removeVehicle(Vehicle vehicle) {
        getVehicles().remove(vehicle);
        vehicle.setBranch(null);
        return vehicle;
    }

    //bi-directional many-to-one association to Warehouse
    @OneToMany(mappedBy = "branch", fetch = FetchType.EAGER)
    public Set<Warehouse> getWarehouses() {
        return this.warehouses;
    }

    public void setWarehouses(Set<Warehouse> warehouses) {
        this.warehouses = warehouses;
    }

    public Warehouse addWarehouse(Warehouse warehouse) {
        getWarehouses().add(warehouse);
        return warehouse;
    }

    public Warehouse removeWarehouse(Warehouse warehouse) {
        getWarehouses().remove(warehouse);
        warehouse.setBranch(null);
        return warehouse;
    }
}
